<template>
    <div>
        <p>用户名：<input type="text" name="" id="" v-model="username"></p>
        <p>密码：<input type="text" name="" id="" v-model="password"></p>
        <p><input type="button" value="登录" @click="login"></p>
        <p><input type="button" value="测试" @click="cespro"></p>
        <p><input type="button" value="微博登录" @click="towburl"></p>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            username:'',
            password:'',
            token:localStorage.getItem('token')
        }
    },
    methods: {
        login(){
            var data = {
                "username":this.username,
                'password':this.password
            }
            axios({
                url:'http://127.0.0.1:8000/proapp/login/',
                method:'post',
                data:data
            }).then(res=>{
                console.log(res.data)
                localStorage.setItem('token',res.data.token)
            })
        },
        cespro(){
            //测试携带token请求
            var data = {
                'token':this.token
            }
            axios({
                url:'http://127.0.0.1:8000/proapp/cespro/',
                method:'post',
                data:data
            }).then(res=>{
                console.log(res.data)
            })
        },
        towburl(){
            axios({
                url:'http://127.0.0.1:8000/proapp/weibourl/',
                method:'post'
            }).then(res=>{
                console.log(res.data.data.url)
                window.location.href = res.data.data.url
            })
        }
    },
    created() {

    }
}
</script>

<style scoped>

</style>
